﻿
/**
* 命名空间: Game.TDBehaviorTree
*
* 功 能： 连接类
* 类 名： Connection
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
* V0.01 2019/12/12 16:46:42  
*/




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;

namespace Game.TDBehaviorTree
{
    [System.Serializable]
   public class Connection
    {
        public TDConnectionPoint inPoint;
        public int m_InPointFileIndex;
        public TDConnectionPoint outPoint;
        public int m_OutFileIndex;
        public Action<Connection> OnClickRemoveConnection;

        public Connection(TDConnectionPoint inPoint, TDConnectionPoint outPoint, Action<Connection> OnClickRemoveConnection)
        {
            this.inPoint = inPoint;
            this.outPoint = outPoint;
            this.m_InPointFileIndex = inPoint.Node.m_FileIndex;
            this.m_OutFileIndex = outPoint.Node.m_FileIndex;
            this.OnClickRemoveConnection = OnClickRemoveConnection;
        }

        public void Draw()
        {
            Handles.DrawBezier(
                inPoint.Rect.center,
                outPoint.Rect.center,
                inPoint.Rect.center + Vector2.left * 50f,
                outPoint.Rect.center - Vector2.left * 50f,
                Color.white,
                null,
                2f
            );

            if (Handles.Button((inPoint.Rect.center + outPoint.Rect.center) * 0.5f, Quaternion.identity, 4, 8, Handles.RectangleCap))
            {
                if (OnClickRemoveConnection != null)
                {
                    OnClickRemoveConnection(this);
                }
            }
        }


        public void DeSerizable(List<NodeValue>_allValue, Action<Connection> OnClickRemoveConnection)
        {
            inPoint = _allValue[m_InPointFileIndex].m_InPoint;
            outPoint= _allValue[m_OutFileIndex].m_OutPoint;
            this.OnClickRemoveConnection = OnClickRemoveConnection;
        }
    }
}
